import Vue from "vue";
console.log("import-vue", Vue);
export default function tabLoad() {
  console.log("Vue", Vue);
  Vue.directive("cong", {
    bind: function (e, binding) {
      console.log("into global");
      let that = binding.value.that;
      let timer = binding.value.timer;
      let meth = binding.value.meth;
      //   let pageOb = binding.value.pageOb;
        let pageSize = binding.value.pageSize;
      //   console.log('pageOb:::',pageOb);
        console.log('pageSize:::',pageSize);
      //   console.log('that[pageOb][pageSize]:::',that[pageOb]);
      setTimeout(() => {
        let elFather = e.querySelector(".el-table__body-wrapper");
        let elSon = e.querySelector(".el-table__body");
        let row = elSon.querySelector(".el-table__row").clientHeight;
        let top = elFather.scrollTop;
console.log('row-h',row);
        elFather.style["height"] = binding.value.fh + "px";// 根据参数给高度
        // elFather.style["height"] =( (row*pageSize) - top)+'px'// 动态计算高度
        elFather.style["overflow"] = "auto";
        elFather.style["overflow-x"] = "hidden";
        console.log("elFather check", elFather);
     
        let fH = elFather.clientHeight;
        let sH = elSon.clientHeight;
        console.log('fH:',fH);
        console.log('sH:',sH);
   
        elFather.addEventListener("scroll", (e) => {
          // console.log("e", e);
  
          if (sH - fH + 20 >= top) {
            // that[pageOb][pageSize]+= 1;
            that.pageOb.pageSize += 1;
            clearTimeout(timer);
            timer = setTimeout(() => {
              that[meth]();
              console.log("调用接口啦");
            }, 500);
          }
        });
      }, 100);
    },
  });
}
